<!DOCTYPE html>
<html lang="en">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title><?php echo $B['title'];?></title>
		<meta name="author" content="Administrator" />
		<link href="/res/bootstrap/css/bootstrap.css" rel="stylesheet" media="screen" />
		<link href="/res/js/artDialog4.1.6/skins/default.css" rel="stylesheet" media="screen"/>
	</head>
	<style>
	.q_box{	border:1px solid silver; padding:10px; }
	.item_box ol{padding:5px;margin-bottom: 0;}
	.item_box li>span{float: right;font-size: 9.5pt;}
	html,body{overflow-x: hidden;}
	</style>
	<script src="/res/js/jquery-1.9.0.js"></script>
	<script src="/res/bootstrap/js/bootstrap.js"></script>
	<script src="/res/js/artDialog4.1.6/jquery.artDialog.js"></script>
	<script src="/res/js/artDialog4.1.6/plugins/iframeTools.js"></script>
	<body>
		<div class="navbar-inner navbar-static-top" style="height:30px; padding-top:8px;">
			<ul class="nav nav-pills" style="float: right;">
				<?php if(isset($_SESSION['uid'])):?>
				<li class="<?php echo t::get('c')=="vote"&&t::get('a')=="my"?"active":"";?>">
					<a href="/?c=vote&a=my&rand=<?php echo rand();?>">我发起的投票</a>
				</li>
				<li class="<?php echo t::get('c')=="vote"&&t::get('a')=="voted"?"active":"";?>">
					<a href="/?c=vote&a=voted&rand=<?php echo rand();?>">我参与的投票</a>
				</li>
				<li class="<?php echo t::get('c')=="vote"&&t::get('a')=="add"?"active":"";?>">
					<a href="/?c=vote&a=add&rand=<?php echo rand();?>">发起新投票</a>
				</li>
				<?php endif;?>
				<li>
					<?php if(isset($_SESSION['uid'])):?>
					<a href="/?c=index&a=logout">(<?php echo t::out($_SESSION['user']['Name']);?>)退出登录</a>
					<?php else:?>
					<a href="javascript:;" onclick="show_login();">登录系统</a>
					<?php endif;?>
				</li>
			</ul>
			<div id="site_name" class="label" style="font-size: x-large;max-width:170px;padding:10px;">
				<a href="/?rand=<?php echo rand();?>" title="TopCoder.Me" style="color:#FFF;">TopCoder.Me</a>
			</div>
		</div>
		<div class="clearfix"></div>
		<div class="container-fluid">
			<div class="row-fluid">
				<div class="left_bar span9">										
					<div class="well" style="font-size: 9.5pt;">
						<span class="label label-important" style="margin:0px 5px;">重要</span>
						本系统仅作为本人(mfy)向杭州Falafel Games展示笔试作品之用。保留一切权利。
					</div>
					<div class="clearfix"></div>
					<?php echo isset($B['data'])?$B['data']:'';?>
					<div class="clearfix"></div>
				</div>
				<div class="right_bar span3" style="padding:15px 0;">
                    <div class="item_box well well-small">
                        <div class="label" style="width:98%;text-align: center;">最热投票</div>
	                    <ol>
	                    	<?php foreach($B['hots'] as $k=>$v):?>
	                    	<li>
	                    		<span><?php echo $v['VoteNum']?>人参与</span>
	                    		<a href="<?php echo BASE_URL;?>/?c=vote&a=view&id=<?php echo $v['Id']?>&rand=<?php echo rand()?>">
	                    			<?php echo t::out($v['Name']);?></a>
	                    		</li>
	                    	<?php endforeach;?>
	                    </ol>
                    </div>
                    <div class="item_box well well-small">
                        <div class="label" style="width:98%;text-align: center;">最新投票</div>
                        <ol>
                            <?php foreach($B['lasts'] as $k=>$v):?>
	                    	<li>
	                    		<span><?php echo date("Y-m-d",$v['CreateTime']);?></span>
	                    		<a href="<?php echo BASE_URL;?>/?c=vote&a=view&id=<?php echo $v['Id']?>&rand=<?php echo rand()?>">
	                    			<?php echo t::out($v['Name']);?></a>
	                    		</li>
	                    	<?php endforeach;?>
                        </ol>
                    </div>
				</div>
			</div>
		</div>
		<!-- <div class="clearfix"></div> -->
		<div id="loginbox" style="display: none;">
            <form class="form-actions" id="login_form" action="/?rand=<?php echo rand();?>" methond="post" style="margin:0px;">
            	<input type="hidden" name="c" value="index"/>
            	<input type="hidden" name="a" value="login"/>
                <div class="controls">
                    <input type="text" id="inputEmail" name="username" placeholder="Email or Username">
                </div>
                <div class="controls">
                    <input type="password" id="inputPassword" name="password" placeholder="Password">
                </div>
                <div class="control-group" style="text-align: right; font-size:9.5pt;">
                	<a href="javascript:;" onclick="art.dialog.show('此功能待完善!');" title="向注册邮箱发送密码重置邮件">忘记密码?</a>&nbsp;|&nbsp;
               		<a href="javascript:;" id="reg_new_lnk" title="注册新用户">尚未注册?</a>	               		
               	</div>
               	<div style="text-align: center;">   
					<input type="submit" class="btn btn-primary btn-small" value="登录"/>
					<input type="reset" class="btn btn-small" value="重置"/>
				</div>
            </form>
		</div>
		<div id="regbox" style="display: none;margin: 0px;">
            <form class="form-actions" id="reg_form" method="post" action="/?rand=<?php echo rand();?>" style="margin:0px;">
            	<input type="hidden" name="c" value="index"/>
            	<input type="hidden" name="a" value="reg"/>
                <div class="controls">
                    <input type="text" id="inputEmail" name="email" placeholder="Email地址">
                </div>
                <div class="controls">
                    <input type="text" id="inputUsername" name="username" placeholder="用户名,2~10个中英文\数字\下划线">
                </div>
                <div class="controls">
                    <input type="password" id="inputPassword" name="password" placeholder="密码,6-16为英文\数字\下划线">
                </div>
                <div class="control-group" style="text-align: right; font-size:9.5pt;">
               		<a href="javascript:;" id="back_to_login" title="前往登录">已经注册过?</a>	               		
               	</div>
               	<div style="text-align: center;">   
	               	<div class="btn-group">
						<input type="submit" class="btn btn-primary" value="注册"/>
						<input type="reset" class="btn btn-inverse" value="重置"/>
					</div>
				</div>
            </form>
		</div>
	</body>
<script>
function show_login(){
	var dialog1 = art.dialog({
		id:'login_dialog',
		content:$('#loginbox')[0],
		title:"欢迎登陆",
		padding:0
	});
	art.dialog({id:'login_dialog'}).show();
	$('#login_form #inputEmail').focus();
}
$(function(){	
	<?php if(!isset($_SESSION['uid'])):?>
	setTimeout(function(){
		show_login();
	},2000);
	<?php endif;?>
	
	var email_exp = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
	var username_exp = /^[0-9a-zA-Z\u4e00-\u9fa5]{2,10}$/i;
	var password_exp = /^[A-Za-z0-9_]{6,16}$/;
	
	$("#reg_new_lnk").click(function(){
		art.dialog({id:'login_dialog'}).hide();
		art.dialog({
			id:'reg_dialog',
			content:$('#regbox')[0],
			title:"欢迎注册",
			padding:0
		});
		art.dialog({id:'reg_dialog'}).show();
	});
	
	$("#back_to_login").click(function(){
		art.dialog({id:'reg_dialog'}).hide();
		show_login();
	});
	
	//注册按钮
	$("#reg_form").submit(function(){
		if(!email_exp.test($('#reg_form #inputEmail').val())){
			art.dialog.alert("您的email地址似乎不正确!");
			return false;
		}
		if(!username_exp.test($('#reg_form #inputUsername').val())){
			art.dialog.alert("用户名限制为2~10个中英文\数字\下划线!");
			return false;
		}
		if(!password_exp.test($('#reg_form #inputPassword').val())){
			art.dialog.alert("密码应为6-16为英文\数字\下划线!");
			return false;
		}
		$.post(
			'/?c=index&a=reg&rand='+Math.random(),
			$("#reg_form").serialize(),
			function(data){
				if(data.succeed == 1){
					art.dialog({id:'reg_dialog'}).hide();		
					art.dialog.tips("恭喜您注册成功!请登录!",1.5);
					setTimeout(function(){show_login();},1500);
				}else{
					art.dialog.alert(data.msg);
					return false;
				}
			},
			'json'
		);
		return false;
	});
	
	//登录按钮
	$("#login_form").submit(function(){
		if($.trim($('#login_form #inputEmail').val())==''){
			art.dialog.alert("您尚未填写email或者用户名!");
			$('#login_form #inputEmail').focus();
			return false;
		}
		if($.trim($('#login_form #inputPassword').val())==''){
			art.dialog.alert("您尚未填写密码!");
			$('#login_form #inputPassword').focus();
			return false;
		}
		$.post(
			'/?c=index&a=login&rand='+Math.random(),
			$("#login_form").serialize(),
			function(data){
				if(data.succeed == 1){
					art.dialog.tips("恭喜您登录成功!请稍后!",2);
					setTimeout(function(){
						window.location.href = "/?c=index&rand="+Math.random();
					},1500);
				}else{
					art.dialog.alert(data.msg);
					return false;
				}
			},
			'json'
		);
		return false;
	});
});
</script>
</html>

